<template>
  <Layout>
    <Form ref="form1" :model="form1" :label-width="120">

      <Row class="query-form" style="padding-top: 15px">
        <Col span="6">
          <FormItem label="审计计划：">
            <Select v-model="form1.planTaskId" style="width: 100%">
              <Option v-for="plan in planList" :key="plan.auditPlanId" :value="plan.auditPlanId">
                {{ plan.auditPlanName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="二级集团：">
            <Select v-model="form1.twoOrgCode" style="width: 100%">
              <Option v-for="item in twoOrgList" :key="item.orgId" :value="item.orgCode">
                {{ item.orgName }}
              </Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="12">
          <Button class="ivu-btn-reset" @click="reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="selects">查询</Button>
          <Dropdown @on-click="downloadFiles" style="float: right">
            <Button class="down">
              导出
              <Icon type="ios-arrow-down"></Icon>
            </Button>
            <Dropdown-menu slot="list">
              <Dropdown-item name="downloadAuditBright">审计亮点导出</Dropdown-item>
              <Dropdown-item name="download">基础和班组详细分析导出</Dropdown-item>
              <Dropdown-item name="downloadScene">现场详细分析导出</Dropdown-item>
              <Dropdown-item name="downloadTop10BasicAndTeam">基础和班组高频扣分导出</Dropdown-item>
              <Dropdown-item name="downloadTop10Scene">现场高频扣分导出</Dropdown-item>
            </Dropdown-menu>
          </Dropdown>
          <!--          <Button class="ivu-btn-query" :loading="buttonLoading3" icon="md-cloud-download" @click="downloadAuditBright">
                      审计亮点导出
                    </Button>
                    <Button class="ivu-btn-query" :loading="buttonLoading1" icon="md-cloud-download" @click="download">
                      基础和班组详细分析导出
                    </Button>
                    <Button class="ivu-btn-query" :loading="buttonLoading2" icon="md-cloud-download" @click="downloadScene">
                      现场详细分析导出
                    </Button>-->
        </Col>
      </Row>
    </Form>

    <Row :gutter="10" class="card-row">
      <Col span="12">
        <Card dis-hover>
          <Spin fix v-if="problemShow">
            <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
            <div>Loading</div>
          </Spin>
          <div ref="problemNum" style="height: 300px;"></div>
        </Card>
      </Col>
      <Col span="12">
        <Card dis-hover>
          <Spin fix v-if="groupNumShow">
            <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
            <div>Loading</div>
          </Spin>
          <div ref="groupNum" style="height: 300px;"></div>
        </Card>
      </Col>
    </Row>
    <Row :gutter="10" class="card-row">
      <Col span="12">
        <Card dis-hover>
          <Spin fix v-if="groupGradeShow">
            <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
            <div>Loading</div>
          </Spin>
          <div ref="groupGrade" style="height: 300px;"></div>
        </Card>
      </Col>
      <Col span="12">
        <Card dis-hover >
          <Spin fix v-if="totalProblemShow">
            <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
            <div>Loading</div>
          </Spin>
          <div  ref="totalProblem" style="height: 300px;"></div>
        </Card>
      </Col>
    </Row>

    <Row :gutter="10" class="card-row">
      <Col span="12">
        <Card dis-hover>
          <p class="title">
            基础标准高频扣分项目统计
          </p>
          <Table ref='basic'  :height="300" no-data-text="没有查询到相关数据！"
                 :loading="groupIntersectionShow" size="small" :columns="groupTable" :data="basicsList">
          </Table>
        </Card>
      </Col>
      <Col span="12">
        <Card dis-hover >
            <p class="title">
              班组标准高频扣分项目统计
            </p>
          <Table ref='team' :height="300" no-data-text="没有查询到相关数据！"
                 :loading="groupIntersectionShow" size="small"  :columns="groupTable" :data="teamList">
          </Table>
        </Card>
      </Col>
    </Row>
    <Row :gutter="10" class="card-row">
      <Col span="24">
        <Card dis-hover >
          <Spin fix v-if="groupGradeColumnShow">
            <Icon type="ios-loading" size=18 class="demo-spin-icon-load"></Icon>
            <div>Loading</div>
          </Spin>
          <div ref="groupGradeColumn" style="height: 300px;"></div>
        </Card>
      </Col>
    </Row>


    <Modal :title="title" :transfer=false v-model="model1" :width=1200 footer-hide>
      <Table ref='table' :height="tableHeight" no-data-text="没有查询到相关数据！"
             :loading="loading" size="small" border :columns="columns1" :data="dataTable">
      </Table>
      <Row style="margin-right:10px;">
        <Col span="24">
          <Page :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange"
                style="float: right" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray"
                show-total show-sizer show-elevator/>
        </Col>
      </Row>
    </Modal>
  </Layout>
</template>

<script>
import {Api} from '../../../../api/index.js'
import {sessionStorage} from '../../../../common/cacheUtils.js';
import cascaderDom from '../../../../components/cascader-dom.vue';
import echarts from 'echarts';
import {formatDate} from "@/tools";

export default {
  components: {cascaderDom},
  name: "riskStatical",
  data() {
    return {
      basicsList: [],
      teamList: [],
      planList: [],
      buttonLoading1: false,
      buttonLoading2: false,
      buttonLoading3: false,
      twoOrgList: [],
      title: '',
      jinyu: [],
      problemShow: true,
      date: ['', ''],
      loading: false,
      problemNumList: [],
      tableHeight: '',
      form1: {},
      planData: [],
      type: '',
      pageSizeArray: [10, 20, 50],
      pagedata: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      scoringRate: [],
      groupNumShow: true,
      groupGradeShow: true,
      groupGradeColumnShow: true,
      companyId: sessionStorage('userId').getObject('userId').companyId,
      dataTable: [],
      groupIntersectionShow: true,
      totalProblemShow: true,
      groupTable: [
        {
          title: "序号",
          width: 80,
          align: "center",

          render: (h, params) => {
            return h('span', params.index + 1);
          }
        },
        {
          title: '扣分次数',
          width: 90,
          align: 'center',
          key: 'num',
        },
        {
          title: '扣分占比',
          width: 90,
          align: 'center',
          key: 'numRate',
        },
        {
          title: '审计内容',
          minWidth: 120,
          align: 'center',
          key: 'subitemName',
          tooltip: true,
        },
      ],
      columns1: [

        {
          title: "序号",
          width: 80,
          align: "center",
          fixed: 'left',
          render: (h, params) => {
            return h('span', params.index + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
          }
        },
        {
          title: '二级集团',
          minWidth: 280,
          align: 'center',
          key: 'twoOrgName',
        },
        {
          title: '审计单位',
          minWidth: 280,
          align: 'center',
          key: 'orgName',
        },
        {
          title: '审计计划',
          minWidth: 150,
          align: 'center',
          key: 'auditPlanName',
        },
        {
          title: '审计任务',
          minWidth: 150,
          align: 'center',
          key: 'missionName',
        },
        {
          title: '带队',
          minWidth: 80,
          align: 'center',
          key: 'supervisor',
        },
        {
          title: '组长',
          minWidth: 80,
          align: 'center',
          key: 'groupLeaderName',
        },

        {
          title: '成员',
          minWidth: 300,
          align: 'center',
          key: 'membersName',
        },
        {
          title: '基础标准得分',
          minWidth: 150,
          align: 'center',
          key: 'calculationBasicsScore',
        },
        {
          title: '现场标准得分',
          minWidth: 150,
          align: 'center',
          key: 'calculationSceneScore',
        },
        {
          title: '班组标准得分',
          minWidth: 150,
          align: 'center',
          key: 'calculationTeamScore',
        },
        {
          title: '总分',
          minWidth: 150,
          align: 'center',
          key: 'totalScore',
        },
        {
          title: '得分率',
          minWidth: 150,
          align: 'center',
          key: 'scoreRate',

        },
        {
          title: '最终得分',
          minWidth: 150,
          align: 'center',
          key: 'finalScore',

        },
        {
          title: '评级',
          minWidth: 150,
          align: 'center',
          key: 'level',

        }

      ],
      twoOrgMap: {},
      problemNameList: [],
      totalBasicList: [],
      totalSceneList: [],
      totalTeamList: [],
      problemNames: [],
      model1: false,
      model2: false,
      buttonDisabled: false,
      InputData: {},
      statistical: {},
      groupNum: [],
      groupGrade: [],
      groupGradeColumn: {},
    }
  },
  async mounted() {
    this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
    // this.query()
    await this.selectCodingSort();

  },
  methods: {
    downloadFiles(name) {
      switch (name) {
        case "downloadAuditBright":
          this.downloadAuditBright();
          break;
        case "download":
          this.download();
          break;
        case "downloadScene":
          this.downloadScene();
          break;
        case "downloadTop10BasicAndTeam":
          this.downloadTop10BasicAndTeam();
          break;
        case "downloadTop10Scene":
          this.downloadTop10Scene();
          break;
      }
    },
    downloadTop10BasicAndTeam() {
      let _this = this;
      this.buttonLoading2 = true
      this.$http.get(Api.downloadTop10BasicAndTeam, {
        params: {auditPlanId: _this.form1.planTaskId, twoOrgCode: _this.form1.twoOrgCode},
        responseType: 'blob'      //告诉服务器我们需要的响应格式
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        // aLink.download = "隐患清单导入模版.xlsx" //标题
        aLink.download = "基础和班组高频扣分导出(" + formatDate(new Date(), "yyyy-MM-dd") + ").xlsx" //标题
        aLink.click()
        document.body.appendChild(aLink)
        this.buttonLoading2 = false
      })
    },
    downloadTop10Scene() {
      let _this = this;
      this.buttonLoading2 = true
      this.$http.get(Api.downloadTop10Scene, {
        params: {planId: _this.form1.planTaskId},
        responseType: 'blob'      //告诉服务器我们需要的响应格式
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        // aLink.download = "隐患清单导入模版.xlsx" //标题
        aLink.download = "现场高频扣分导出(" + formatDate(new Date(), "yyyy-MM-dd") + ").xlsx" //标题
        aLink.click()
        document.body.appendChild(aLink)
        this.buttonLoading2 = false
      })
    },
    async getPlanAll() {
      let _this = this;
      await this.$http.get(Api.getPlanAll).then((res) => {

        _this.planList = res.data.data.list;
        if (res.data.data.plan) {
          _this.form1.planTaskId = res.data.data.plan.auditPlanId;
          this.selects();
        } else {
          this.$Message.info("请先选择审计计划")
        }

      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    downloadAuditBright() {
      let _this = this;
      this.buttonLoading3 = true
      this.$http.get(Api.downloadBright + "/" + this.form1.planTaskId, {
            responseType: 'blob'      //告诉服务器我们需要的响应格式
          },
      ).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        aLink.download = "审计亮点(" + formatDate(new Date(), "yyyy-MM-dd") + ").xlsx" //标题
        aLink.click()
        document.body.appendChild(aLink)
        this.buttonLoading3 = false
      })
    },
    download() {
      let _this = this;
      this.buttonLoading1 = true
      this.$http.get(Api.problemCountDownload + "/" + this.form1.planTaskId, {
        params: {year: _this.form1.year},
        responseType: 'blob'      //告诉服务器我们需要的响应格式
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
       // aLink.download = "隐患清单导入模版.xlsx" //标题
        aLink.download = "安全审计基础和班组详细分析(" + formatDate(new Date(), "yyyy-MM-dd") + ").xlsx" //标题
        aLink.click()
        document.body.appendChild(aLink)
        this.buttonLoading1 = false
      })
    },
    downloadScene(){
      let _this = this;
      this.buttonLoading2 = true
      this.$http.get(Api.problemSceneCountDownload+"/"+this.form1.planTaskId, {
        params:{year:_this.form1.year},
        responseType: 'blob'      //告诉服务器我们需要的响应格式
      }).then((res) => {
        const aLink = document.createElement("a");
        let blob = new Blob([res.data], {
          type: res.bodyBlob.type      //将会被放入到blob中的数组内容的MIME类型
        });
        aLink.href = URL.createObjectURL(blob)
        // aLink.download = "隐患清单导入模版.xlsx" //标题
        aLink.download = "安全审计现场详细分析(" + formatDate(new Date(), "yyyy-MM-dd") + ").xlsx" //标题
        aLink.click()
        document.body.appendChild(aLink)
        this.buttonLoading2 = false
      })
    },
    selects() {
      this.selectTotalProNum();
      if (this.form1.planTaskId) {
        this.selectGroupNum();
        this.selectGroupGrade();
        this.selectGroupGradeColumn();
        this.groupIntersection();
        this.selectProblemNum();
      }


    },
    selectOrgInfo(value){
      this.form1.twoOrgId = value;
      this.groupIntersection();
    },
    groupIntersection(){
      let _this = this;
      _this.groupIntersectionShow = true;
      let data = {
        auditPlanId: _this.form1.planTaskId,
        year: _this.form1.year,
        twoOrgCode: _this.form1.twoOrgCode
      }

      this.$http.get(Api.groupIntersection,{params:data}).then((res) => {
        if (res.data.status == '200'){
          _this.basicsList = res.data.data.basics
          _this.teamList = res.data.data.team
        }
        _this.groupIntersectionShow = false;
      }).catch(e => {
        _this.groupIntersectionShow = false;
        this.$Message.error("数据获取失败")
      })
    },
    async selectCodingSort() {
      let _this = this;
      await this.$http.get(Api.getTwoOrgInfo).then((res) => {
        res.data.data.forEach(item =>{
          _this.twoOrgList.push(item);
          _this.twoOrgMap[item['orgName']] = item['orgId'];

        })
      });

      await this.getPlanAll()



    },
    setOrgId(data) {
      this.form1.orgId = data[data.length - 1];
    },
    setOrgName(data) {
      this.form1.orgName = data;
    },
    formatDate(date, fmt) {
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
      };
      for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
          let str = o[k] + '';
          fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
        }
      }
      return fmt;
    },
    padLeftZero(str) {
      return ('00' + str).substr(str.length);
    },
    select() {

    },
    query(name, type) {
      this.loading = true;
      let data = {
        startPage: this.pagedata.currentPage,
        size: this.pagedata.pageSize,

      };

      let queryFrom = {
        ...this.form1
      }
      if (type === '1') {
        queryFrom.twoOrgId = this.twoOrgMap[name];
        queryFrom.twoOrgCode = null;
        queryFrom.twoOrgName = name;
        queryFrom.level = null;
      } else if (type === '2') {
        queryFrom.level = name;
        queryFrom.twoOrgName = null;
      }
      if (queryFrom['planTaskId']) {
        queryFrom['planId'] = queryFrom['planTaskId']
      }
      data = Object.assign(data, JSON.parse(JSON.stringify(queryFrom)));
      let url = Api.queryAuditRank;
      this.dataTable = [];
      this.$http.get(url, {params: data}).then((res) => {
        this.dataTable = res.data.data.data;
        this.pagedata.total = res.data.data.totalSize;
        this.loading = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    reset() {
      this.form1.twoOrgCode = null;
      this.selects();
    },
    pageChange(pageNum) {
      this.pagedata.currentPage = pageNum;
      this.query();
    },
    pageSizeChange(pageSize) {
      this.pagedata.pageSize = pageSize;
      this.query();
    },

    chartStatistical() {
      this.statistical = {
        companyName: [],
        staffNumber: [],
        isPullateCount: [],
        safeRankOne: [],
        safeRankTwo: [],
        safeRankThree: [],
        safeLevelOne: [],
        safeLevelTwo: [],
        healthDateCount: [],
        manageDateCount: []
      }
      for (var i = 0; i < this.dataTable.length; i++) {
        let item = this.dataTable[i]
        this.statistical.companyName.push(item.orgName)
        this.statistical.staffNumber.push(item.staffNumber)
        this.statistical.isPullateCount.push(item.isPullateCount)
        this.statistical.safeRankOne.push(item.safeRankOne)
        this.statistical.safeRankTwo.push(item.safeRankTwo)
        this.statistical.safeRankThree.push(item.safeRankThree)
        this.statistical.safeLevelOne.push(item.safeLevelOne)
        this.statistical.safeLevelTwo.push(item.safeLevelTwo)
        this.statistical.healthDateCount.push(item.healthDateCount)
        this.statistical.manageDateCount.push(item.manageDateCount)
      }
      let container = echarts.init(this.$refs.envinfoContainer);
      let option = this.getOption();
      container.setOption(option);
      window.onresize = container.resize;
    },


    getOption() {
      let option = {
        tooltip: {	//提示框组件
          trigger: 'axis',
          axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        legend: {	//图例组件
          data: ['从业人数', '重点排污单位', '安全标准化等级(一级)',
            '安全标准化等级(二级)', '安全标准化等级(三级)',
            '安全文化示范企业(国家级)', '安全文化示范企业(省市级)',
            '职业健康体系认证', '环境管理体系认证']
        },
        color: ['#FD5C50', '#FF9800', '#FDD835', '#40C4FF', '#FF3E80', '#42A5F5', '#FFC310', '#1DE9B6', '#6666CC', '#66CC66'],
        grid: {
          left: '3%',
          right: '3%',
          bottom: '8%',
          containLabel: true,
        },
        dataZoom: [{
          type: 'inside'
        }, {
          type: 'slider',
          textStyle: false
        }],
        xAxis: [
          {
            type: 'category',
            data: this.statistical.companyName,
            axisLabel: {
              interval: 0,
              formatter: function (value) {
                var str = "";
                var num = 6; //每行显示字数
                var valLength = value.length; //该项x轴字数
                var rowNum = Math.ceil(valLength / num); // 行数
                if (rowNum > 1) {
                  for (var i = 0; i < rowNum; i++) {
                    var temp = "";
                    var start = i * num;
                    var end = start + num;
                    temp = value.substring(start, end) + "\n";
                    str += temp;
                  }
                  return str;
                } else {
                  return value;
                }
              }
            }
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '从业人数',
            type: 'bar',
            emphasis: {
              focus: 'series'
            },
            data: this.statistical.staffNumber
          },
          {
            name: '重点排污单位',
            type: 'bar',
            emphasis: {
              focus: 'series'
            },
            data: this.statistical.isPullateCount
          },
          {
            name: '安全标准化等级(一级)',
            type: 'bar',
            stack: '安全标准化等级',
            emphasis: {
              focus: 'series'
            },
            data: this.statistical.safeRankOne
          },
          {
            name: '安全标准化等级(二级)',
            type: 'bar',
            stack: '安全标准化等级',
            emphasis: {
              focus: 'series'
            },
            data: this.statistical.safeRankTwo
          },
          {
            name: '安全标准化等级(三级)',
            type: 'bar',
            stack: '安全标准化等级',
            emphasis: {
              focus: 'series'
            },
            data: this.statistical.safeRankThree
          },
          {
            name: '安全文化示范企业(国家级)',
            type: 'bar',
            stack: '安全文化示范企业',
            emphasis: {
              focus: 'series'
            },
            data: this.statistical.safeLevelOne
          },
          {
            name: '安全文化示范企业(省市级)',
            type: 'bar',
            stack: '安全文化示范企业',
            emphasis: {
              focus: 'series'
            },
            data: this.statistical.safeLevelTwo
          },
          {
            name: '职业健康体系认证',
            type: 'bar',
            emphasis: {
              focus: 'series'
            },
            data: this.statistical.healthDateCount
          },
          {
            name: '环境管理体系认证',
            type: 'bar',
            emphasis: {
              focus: 'series'
            },
            data: this.statistical.manageDateCount
          }
        ]
      };
      return option;
    },
    selectGroupGradeColumn() {
      let _this = this;
      _this.groupGradeColumnShow = true;
      let container = echarts.init(this.$refs.groupGradeColumn);
      this.$http.get(Api.queryGroupGradeColumn + _this.form1.planTaskId,{params:{year:this.form1.year}}).then((res) => {
        this.groupGradeColumn = res.data.data;
        let option = this.getGroupGradeColumn();
        container.setOption(option);
        window.onresize = container.resize;
        _this.groupGradeColumnShow = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
        _this.groupGradeColumnShow = false;
      })
    },
    getGroupGradeColumn() {
      let option = {
        title:{
          text:"二级集团评分统计",
          left:'left',
          textStyle:{
            fontSize:18,
            fontWeight:"normal"
          }
        },
        tooltip: {	//提示框组件
          trigger: 'axis',
          axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
          }
        },
        legend: {	//图例组件
          x:"right",
          data: ['A', 'B', 'C', 'D',]
        },
        color: ['#FD5C50', '#FF9800', '#FDD835', '#40C4FF', '#FF3E80', '#42A5F5', '#FFC310', '#1DE9B6', '#6666CC', '#66CC66'],
        grid: {
          left: '3%',
          right: '3%',
          bottom: '8%',
          containLabel: true,
        },
        dataZoom: [{
          type: 'inside'
        }, {
          bottom:-5,
          type: 'slider',
          textStyle: false
        }],
        xAxis: [
          {
            type: 'category',
            data: this.groupGradeColumn.names,
            axisTick: {show: false},
            axisLine: {show: false},
            axisLabel: {
              interval: 0,
              formatter: function (value) {
                var str = "";
                var num = 6; //每行显示字数
                var valLength = value.length; //该项x轴字数
                var rowNum = Math.ceil(valLength / num); // 行数
                if (rowNum > 1) {
                  for (var i = 0; i < rowNum; i++) {
                    var temp = "";
                    var start = i * num;
                    var end = start + num;
                    temp = value.substring(start, end) + "\n";
                    str += temp;
                  }
                  return str;
                } else {
                  return value;
                }
              }
            }
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: 'A',
            type: 'bar',
            stack:'group',
            barWidth : 30,
            emphasis: {
              focus: 'series'
            },
            data: this.groupGradeColumn.a
          },
          {
            name: 'B',
            type: 'bar',
            stack:'group',
            barWidth : 30,
            emphasis: {
              focus: 'series'
            },
            data: this.groupGradeColumn.b
          },
          {
            name: 'C',
            type: 'bar',
            stack:'group',
            barWidth : 30,
            emphasis: {
              focus: 'series'
            },
            data: this.groupGradeColumn.c
          },
          {
            name: 'D',
            type: 'bar',
            stack:'group',
            barWidth : 30,
            emphasis: {
              focus: 'series'
            },
            data: this.groupGradeColumn.d
          },
        ]
      };
      return option;

    },
    paseGroupGrade(data) {
      return {
        type: 'pie',
        data: data,
        radius: '65%',
        label: {
          normal: {
            position: 'outseide',
            show: true,
            formatter: '{b}:{c}',
          }
        },
      }
    },

    selectGroupGrade() {
      let _this = this;
      _this.groupGradeShow = true;
      let container = echarts.init(this.$refs.groupGrade);
      this.$http.get(Api.queryGroupGrade + _this.form1.planTaskId, {
        params: {
          year: this.form1.year,
          twoOrgCode: this.form1.twoOrgCode
        }
      }).then((res) => {
        _this.groupGrade = res.data.data;
        let option = this.getGroupGrade();
        if (_this.groupGrade) {
          let groupGrade = _this.paseGroupGrade(_this.groupGrade)
          option.series.push(groupGrade);
        }
        container.setOption(option);
        container.on("click", onSelect);
        function onSelect(param) {
          event.stopPropagation() // 阻止冒泡
          _this.pagedata = {
            total: 0,
            pageSize: 10,
            currentPage: 1,
          }
          _this.title = param.name
          _this.model1 = true;
          _this.query(param.name, '2');
        }

        window.onresize = container.resize;
        _this.groupGradeShow = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
        _this.groupGradeShow = false;
      })
    },
    getGroupGrade() {
      let option = {
        title:{
          text:"审计评分分布情况",
          left:'left',
          textStyle:{
            fontSize:18,
            fontWeight:"normal"
          }
        },
        polar: {
          radius: [20, '80%']
        },
        angleAxis: {
          startAngle: 270,
          axisLabel:{show:false},
          splitLine: {show: false},
          axisTick: {show: false},
          axisLine: {show: false}

        },

        radiusAxis: {
          type: 'category',
          axisLabel:{show:false},
          splitLine: {show: false},
          axisTick: {show: false},
          axisLine: {show: false}

        },
        color: ['#FD5C50', '#FF9800', '#FDD835', '#40C4FF', '#FF3E80', '#42A5F5', '#FFC310', '#1DE9B6', '#6666CC', '#66CC66'],
        tooltip: {
          formatter(params){
            return params.name + '：' + params.value
          }
        },
        series: [

        ],
        legend: {
          show: true,
          orient: 'vertical',
          x:"right",
          y:"center",
          type: 'scroll',

        },

      };
      return option;

    },


    selectGroupNum() {
      let _this = this;
      _this.groupNumShow = true;
      let container = echarts.init(this.$refs.groupNum);
      this.$http.get(Api.queryGroupNum + _this.form1.planTaskId,{params:{year:this.form1.year}}).then((res) => {
        this.groupNum = res.data.data;
        this.groupNum.forEach(item =>{
          _this.$set(item,"labelLine",{show: true, length:1,})
          _this.$set(item,"label",{show: true})
        })
        let option = this.getGroupNum();
        container.setOption(option);
        container.on("click", onSelect);
        function onSelect(param) {
          event.stopPropagation() // 阻止冒泡
          _this.pagedata = {
            total: 0,
            pageSize: 10,
            currentPage: 1,
          }

          _this.title = param.name
          _this.model1 = true;

          _this.query(param.name,'1');
        }

        window.onresize = container.resize;
        _this.groupNumShow = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
        _this.groupNumShow = false;
      })
    },

    getGroupNum() {
      let option = {
        title:{
          text:"审计单位数量统计",
          left:'left',
          textStyle:{
            fontSize:18,
            fontWeight:"normal"
          }
        },
        tooltip:{
          show:true,
        },
        legend: {
          orient: 'vertical',
          x:"right",
          y:"center",
          type: 'scroll',
          itemHeight:10,
          formatter: function (name) {
            if (!name) return '';
            if (name.length > 5) {
              name =  name.slice(0,5) + '...';
              return name
            }
          },
          tooltip: {
            show: true
          }
        },
        color: ['#FD5C50', '#FF9800', '#FDD835', '#40C4FF', '#FF3E80', '#42A5F5', '#FFC310', '#1DE9B6', '#6666CC', '#66CC66'],

        series: [
          {
            name: '审计数量',
            type: 'pie',
            radius:["30%",'70%'],
            center: ['40%', '55%'],
            roseType: 'radius',
            data: this.groupNum,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            },
            label:{
              normal:{
                formatter:function(e){
                  let data=e.data;
                  if(data.value==0){
                    data.labelLine.show=false;
                    data.label.show=false;
                  }else{
                    return data.value
                  }
                },
              }
            },
            stillShowZeroSum:false,
          }
        ]
      };
      return option;

    },


    selectProblemNum(){
      let _this = this;
      _this.problemShow = true;
      let container = echarts.init(this.$refs.problemNum);
      this.$http.get(Api.selectProblemNum + _this.form1.planTaskId, {
        params: {
          year: this.form1.year,
          twoOrgCode: this.form1.twoOrgCode
        }
      }).then((res) => {
        _this.problemNumList = res.data.data;
        let option = this.getProblemNum();
        container.setOption(option);
        window.onresize = container.resize;
        _this.problemShow = false;
      }).catch(e => {
        _this.problemShow = false;
        this.$Message.error("数据获取失败")
      })

    },

    getProblemNum(){
      let option = {
        title:{
          text:"问题统计",
          left:'left',
          textStyle:{
            fontSize:18,
            fontWeight:"normal"
          }
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            // Use axis to trigger tooltip
            type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
          }
        },
        legend: {},
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value',
          splitLine: {show: false},
          axisTick: {show: false},
          axisLine: {show: false}
        },
        yAxis: {
          axisLine: {
            show: false,
          },
          data: [  '已完成整改数量', '班组问题数量','已完成整改数量','现场问题数量', '已完成整改数量','基础问题数量'],
          axisTick: {show: false}
        },
        series: [
          {
            label: {
              show: true
            },
            type: 'bar',
            itemStyle: {
              normal: {
                //这里是重点
                color: function(params) {
                  //注意，如果颜色太少的话，后面颜色不会自动循环，最好多定义几个颜色
                  //,
                  var colorList =['#FFC310', '#FF9800', '#FD5C50','#f34317' , '#42A5F5', '#40C4FF',   ];
                  return colorList[params.dataIndex]
                }
              }
            },
            data: this.problemNumList
          }
        ]
      };
      return option;
    },


    getTotalProNum(){
      let option = {
        title: {
          text:"审计问题总数",
          left:'left',
          textStyle:{
            fontSize:18,
            fontWeight:"normal"
          }
        },
        tooltip: {
          trigger: 'axis'
        },
        color: ['#FD5C50', '#FF9800', '#FDD835', '#40C4FF', '#FF3E80', '#42A5F5', '#FFC310', '#1DE9B6', '#6666CC', '#66CC66'],
        legend: {
          data: ["基础问题","现场问题","班组问题"],
          x:"right"
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },

        xAxis: {
          type: 'category',

          data: this.problemNameList
        },
        yAxis: {
          type: 'value',
          axisTick: {show: false},
          axisLine: {show: false},
        },
        series: [
          {
            name: '基础问题',
            type: 'line',

            smooth: true,
            data: this.totalBasicList
          },
          {
            name: '现场问题',
            type: 'line',

            smooth: true,
            data: this.totalSceneList
          },
          {
            name: '班组问题',
            type: 'line',

            smooth: true,
            data: this.totalTeamList
          },

        ]
      };
      return option;
    },

    selectTotalProNum(){
      let _this = this;
      _this.totalProblemShow = true;
      let container = echarts.init(this.$refs.totalProblem);
      this.$http.get(Api.selectTotalProblemNum, {params: {twoOrgCode: this.form1.twoOrgCode}}).then((res) => {
        _this.totalBasicList = res.data.data.basicList;
        _this.totalSceneList = res.data.data.sceneList;
        _this.totalTeamList = res.data.data.teamList;
        _this.problemNameList = res.data.data.problemName;
        let option = this.getTotalProNum();
        container.setOption(option);
        window.onresize = container.resize;
        _this.totalProblemShow = false;
      }).catch(e => {
        _this.totalProblemShow = false;
        this.$Message.error("数据获取失败")
      })

    },







  }
}
</script>

<style >
@import '../../../../index.css';

.demo-spin-icon-load {
  animation: ani-demo-spin 1s linear infinite;
}
.card{
  height: 332px;
  overflow-y:auto;
}

.card-row {
  margin-bottom: 10px;
}

.title {
  font-size: 18px;
  font-weight: normal;
}

.down {

  background: #F65555;
  border-color: #F65555;
  height: 30px;
  font-size: 14px;
  font-family: Microsoft YaHei;
  color: #FFFFFF;

}

.down:hover {
  height: 30px;
  background: #F27874;
  border-radius: 4px;
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #FFFFFF;
}

</style>
